package uit.nfc.utils;

import uit.nfc.nfcmenudishes.NfcMenuActivity;
import uit.nfc.nfcmenudishes.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class SpinnerAdapter extends ArrayAdapter<DishesItem> {
	
	public SpinnerAdapter(Context context, int textViewResourceId, DishesItem[] objects) {
		super(context, textViewResourceId, objects);
	}

	@Override
	public View getDropDownView(int position, View convertView, ViewGroup parent) {
		return getCustomView(position, convertView, parent);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		return getCustomView(position, convertView, parent);
	}
	
	public View getCustomView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = ((NfcMenuActivity)this.getContext()).getLayoutInflater();
        View row = inflater.inflate(R.layout.spinner_row, parent, false);
        
        ImageView image = (ImageView)row.findViewById(R.id.image_spinner_row);
        TextView dishes = (TextView)row.findViewById(R.id.dishes_spinner_row);
        TextView description = (TextView)row.findViewById(R.id.description_spinner_row);
        
        if (position > 0) {
        	image.setImageResource(R.drawable.cocktail2);
        	
        	dishes.setText(this.getItem(position).getName());
        	description.setText(this.getItem(position).getDescription());
        } else {
        	description.setText("Select dishes...");
        }

        return row;
	}
}
